<?php

namespace App\Http\Controllers\Api;

use App\Common\Libs\ArrayHelper;
use App\Consts\GlobalSalonConst;
use App\Exceptions\Error;
use App\Http\Controllers\BaseController;
use App\Models\Field\SalonField;
use Illuminate\Http\Request;

class SalonController extends BaseController
{
    public $validate = [
        "getDetail" => [
            "rules" => [
                "id" => "required|string|max:24",
            ]
        ],
    ];

    /**
     * @path /salon/list
     * @category 沙龙
     * @title 列表
     * @method POST
     * @resBody {"success":true,"statusCode":200,"result":[{"id":"沙龙ID","user_id":"用户ID","cover_url":"沙龙封面图，如1.jpg","title":"沙龙标题","address":"沙龙地址","status":"状态，0即将开幕，1进行中，2已结束，3往期回顾","start_at":"开始时间戳","end_at":"结束时间戳","created_at":"创建时间戳","advance":"预告内容","review":"回顾内容","user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg","special_signature":"用户个性签名","attention_status":"关注状态，0没关系，1关注，2粉丝，3互关"}}],"message":"OK"}
     */
    public function getList(Request $request)
    {
        $searchParams = [
            'current_user_id' => $this->getCurrentUserId(),
            'is_review' => GlobalSalonConst::IS_NOT_REVIEW
        ];

        $replyList = service()->SalonService->getSalonList($searchParams);

        return $this->apiReturn($replyList);
    }

    /**
     * @path /salon/review
     * @category 沙龙
     * @title 往期回顾列表
     * @method POST
     * @resBody {"success":true,"statusCode":200,"result":[{"id":"沙龙ID","user_id":"用户ID","cover_url":"沙龙封面图，如1.jpg","title":"沙龙标题","address":"沙龙地址","status":"状态，0即将开幕，1进行中，2已结束，3往期回顾","start_at":"开始时间戳","end_at":"结束时间戳","created_at":"创建时间戳","advance":"预告内容","review":"回顾内容","is_enable":"是否启用，0禁用，1启用","user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg","special_signature":"用户个性签名","attention_status":"关注状态，0没关系，1关注，2粉丝，3互关"}}],"message":"OK"}
     */
    public function reviewList(Request $request)
    {
        $params = $request->all();
        $searchParams = [
            'status' => GlobalSalonConst::STATUS_REVIEW,
            'page' => !empty($params['page']) ? $params['page'] - 1 : 0,
            'current_user_id' => $this->getCurrentUserId(),
            'is_review' => GlobalSalonConst::IS_REVIEW
        ];

        $replyList = service()->SalonService->getReviewSalonList($searchParams);

        return $this->apiReturn($replyList);
    }

    /**
     * @path /salon/get-detail
     * @category 沙龙
     * @title 详情
     * @method POST
     * @params [{"name":"id","type":"text","required":1,"example":"","desc":"沙龙ID"}]
     * @resBody {"success":true,"statusCode":200,"result":[{"id":"沙龙ID","user_id":"用户ID","cover_url":"沙龙封面图，如1.jpg","title":"沙龙标题","address":"沙龙地址","status":"状态，0即将开幕，1进行中，2已结束，3往期回顾","start_at":"开始时间戳","end_at":"结束时间戳","created_at":"创建时间戳","advance":"预告内容","review":"回顾内容","lng":"120","lat":"68","apply_information":"这是报名须知","user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg","special_signature":"用户个性签名","attention_status":"关注状态，0没关系，1关注，2粉丝，3互关"}}],"message":"OK"}
     */
    public function getDetail(Request $request)
    {
        $salonId = $request->post('id');

        $salon = service()->SalonService->getSalonBySalonId($salonId);
        if (!$salon) {
            return $this->apiReturn(Error::handle());
        }

        $salon = ArrayHelper::merge($salon->commonFormat(SalonField::SELF_DETAIL), service()->SalonService->getSalonMoreFields($salon, $this->getCurrentUserId()));

        return $this->apiReturn($salon);
    }
}
